package com.duqc.redis.lock;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName RedisLockController
 * @Description redis分布式锁
 * @Author duqc
 * @Date 2022/10/26
 **/
@Slf4j
@RestController
public class RedisLockController {

    @GetMapping("/testRedisLock")
    @RedisLockAnnotation(typeEnum = RedisLockTypeEnum.ONE, lockTime = 3)
    public String testRedisLock(@RequestParam("userId") Long userId) {
        try {
            log.info("睡眠执行前");
            Thread.sleep(1000);
            log.info("睡眠执行后");
        } catch (InterruptedException e) {
            // log error
            log.info("has some error", e);
            Thread.currentThread().interrupt();
        }
        return null;
    }

}
